<template>
  <div class="box">
		<h3>企业名称：{{companyName}}</h3>
		<p v-show="goodsDetail.ptGoodsPlanId">所属商品计划：{{ptGoodsPlan}}</p>
		<p>商品名称：{{goodsDetail.name}}</p>
		<p v-show="goodsDetail.remark">商品简介：{{goodsDetail.remark}}</p>
		<p>
      <span class="pr">商品生效时间：{{goodsDetail.beginTimeValue}}</span>
      <span>商品失效时间：{{goodsDetail.endTimeValue}}</span>
    </p>
		<h3>产品绑定优加服务：</h3>
    <p>
      <span class="pr" v-show="goodsDetail.youCashPrePayId">押金垫付</span>
      <span class="pr" v-show="goodsDetail.youPhoneDoctorId">电话医生</span>
      <span class="pr" v-show="goodsDetail.youBodyCheck">体检服务</span>
      <span class="pr" v-show="goodsDetail.youOutpatient">门诊绿通</span>
      <span class="pr" v-show="goodsDetail.youHospital">住院绿通</span>
      <span class="pr" v-show="goodsDetail.youOperation">手术绿通</span>
      <span v-show="goodsDetail.youSecondMed">二次诊疗</span>
    </p>

    <you-cash :id="goodsDetail.youCashPrePayId"></you-cash>
    <you-doctor :id="goodsDetail.youPhoneDoctorId"></you-doctor>
    
		<h3>修改人：{{operatorName}}</h3>
    <p>修改时间： {{goodsDetail.updateTimeValue}}</p>
		<p v-if="operatorType === '修改'">修改原因：{{goodsDetail.reason}}</p>
		<p v-else>修改原因：{{goodsDetail.reason}}</p>
		<!-- <p>相关附件：</p> -->
		<div>
			<el-button type="success" class="btn" @click="done(true)">同意</el-button>
			<el-button type="warning" plain class="btn" @click="done(false)">拒绝</el-button>
		</div>
  </div>
</template>

<script>
const queryString = require('querystring')
import youCash from './controls/youCash'
import youDoctor from './controls/youDoctor'
export default {
  name: 'comInfo',
  components: {
    youCash,
    youDoctor
  },
  data() {
    return {
      id: this.$route.query.id,
      checkedValue: ['押金垫付'],
      userveList: ['押金垫付', '电话医生'],
      operatorType: this.$route.query.operatorType,
      goodsDetail: {},
      operatorName: '',
      ptCashPrePay: {},
      ptPhoneDoctor: {},
      companyName: '',
      ptGoodsPlan: ''
    }
  },
  created() {
    this.getDetail()
    
  },
  methods: {
    getDetail() {
			this.axios.get(`/goods/${this.id}/detail`).then((res) => {
              const data = res.data
              const code = Number(data.code)
              if (code === 200) {
                  this.operatorName = data.data.operatorName
                  this.goodsDetail = data.data.modified
                  this.goodsDetail.beginTimeValue = this.timeFormater(this.goodsDetail.beginTime).format('YYYY-MM-DD')
                  this.goodsDetail.endTimeValue = this.timeFormater(this.goodsDetail.endTime).format('YYYY-MM-DD')
                  this.goodsDetail.updateTimeValue = this.timeFormater(this.goodsDetail.updateTime).format('YYYY-MM-DD')
                  this.getGoodsPlanList()
                  this.getCompanyList()
              } else {
                  this.$message(this.mes.busy)
              }
            }).catch((err) => {
              console.log(err)
              this.$message(this.mes.busy)
            })
		},
    done(status) {
      const params = {
        id: this.id,
        confirm: status
      }
      this.axios.post(`/goods/${this.id}/detail/confirm` , queryString.stringify(params)).then((res) => {
              const code = Number(res.data.code)
              if (code === 200) {
                  this.$message(this.mes.success)
                  this.$router.push('infoRecheck?activeName=2')
              } else {
                  this.$message(this.mes.busy)
              }
            }).catch((err) => {
              console.log(err)
              this.$message(this.mes.busy)
            })
    },
    getCompanyList() {
      this.axios.get(`/company?page=0&size=1000`).then(res => {
        if (res.data.code == 200) {
          this.companyList = res.data.data.list
          this.companyName = this.id2Name(this.companyList, this.goodsDetail.companyId)
          console.log(this.companyName)
        }
      })
      .catch(err => {
        console.log(err)
      });
    },
    getGoodsPlanList() {
      const params = {
        companyId: this.goodsDetail.companyId,
        // page: this.currentPage - 1,
        // size: 20
      };
      this.axios
        .get('/goodsPlan?' + queryString.stringify(params))
        .then(res => {
          const code = Number(res.data.code);
          if (code === 200) {
            this.goodsPlanList = res.data.data;
            console.log(this.goodsPlanList)
            this.ptGoodsPlan = this.id2Name(this.goodsPlanList, this.goodsDetail.ptGoodsPlanId)
            console.log(this.ptGoodsPlan)
            // this.setPage(res.data.data);
          } else {
            this.$message(this.mes.busy);
          }
        })
        .catch(err => {
          console.log(err);
          this.$message(this.mes.busy);
        });
    }
  }
}
</script>

<style lang="less" scoped>
.box{
	padding-left: 50px
}
 .btn{
    margin-left: 20px;
  }
  .pr{
    padding-right: 20px
  }
</style>
